//
//  BBGestureBaseController.m
//  TmChat
//
//  Created by Stn on 2019/9/18.
//  Copyright © 2019 onlysea. All rights reserved.
//

#import "BBGestureBaseController.h"

@interface BBGestureBaseController ()
{
    NSString *Tag;
}
@end

@implementation BBGestureBaseController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    if ([self.navigationController.viewControllers indexOfObject:self] != 0) {
        self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Nav_back"] style:UIBarButtonItemStyleDone target:self action:@selector(leftClick:)];
        
    }
    self.view.backgroundColor = kColorFromRGB(244, 244, 244);
    self.navigationController.navigationBar.translucent=NO;
}
-(void)CreateNavRightButtonWithTitle:(NSString *)title
{
    UIButton *Nav_RightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    NSAttributedString *NsAttStr = [[NSAttributedString alloc]initWithString:title attributes:@{NSForegroundColorAttributeName : kColorFromRGBHex(0xFFA200),NSFontAttributeName : KMEDIUM(17)}];
    [Nav_RightBtn setAttributedTitle:NsAttStr forState:UIControlStateNormal];
    [Nav_RightBtn addTarget:self action:@selector(FinishFunction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:Nav_RightBtn];
    Nav_RightBtn.frame = CGRectMake(0, 0, 44, 44);
        Nav_RightBtn.contentEdgeInsets = UIEdgeInsetsMake(-2, 0, 2,0);
}
-(void)CreateNavRightButtonWithTitle:(NSString *)title forTag:(NSString *)tag
{
    Tag = tag;
    UIButton *Nav_RightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    NSAttributedString *NsAttStr = [[NSAttributedString alloc]initWithString:title attributes:@{NSForegroundColorAttributeName : kColorFromRGBHex(0xFFA200),NSFontAttributeName : KMEDIUM(17)}];
    [Nav_RightBtn setAttributedTitle:NsAttStr forState:UIControlStateNormal];
    [Nav_RightBtn addTarget:self action:@selector(FinishFunction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:Nav_RightBtn];
    Nav_RightBtn.frame = CGRectMake(0, 0, 44, 44);
    Nav_RightBtn.contentEdgeInsets = UIEdgeInsetsMake(-2, 0, 2,0);
}
-(void)CreateNavRightItemWithTitle:(NSString *)title
{
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithTitle:title style:UIBarButtonItemStyleDone target:self action:@selector(rightClick:)];
    [item setTintColor:ColorMain];
    [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:KMEDIUM(17),NSFontAttributeName, nil] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem=item;
}
-(void)FinishFunction
{
    if (_BBdelegate && [_BBdelegate respondsToSelector:@selector(clickRightItemWithViewController:)]) {
        [_BBdelegate clickRightItemWithViewController:self];
    }
}
-(void)FinishFunction:(NSString *)tag
{
    tag = Tag;
    if (_BBdelegate && [_BBdelegate respondsToSelector:@selector(clickRightItemWithViewController:forTag:)]) {
        [_BBdelegate clickRightItemWithViewController:self forTag:tag];
    }
}
-(void)rightClick:(UIBarButtonItem *)item{
    if (_BBdelegate && [_BBdelegate respondsToSelector:@selector(clickRightItemWithBarButtonItem:)]) {
        [_BBdelegate clickRightItemWithBarButtonItem:item];
    }
}
-(void)leftClick:(UIBarButtonItem *)item{
    if (_BBdelegate && [_BBdelegate respondsToSelector:@selector(GoBackVc:)]) {
        [_BBdelegate GoBackVc:self];
    }else
    {
    [self.navigationController popViewControllerAnimated:YES];
    }
}





@end
